public class Leet82 {
    public ListNode deleteDuplicates(ListNode head) {
        int num;
        ListNode list = new ListNode();
        boolean flag = false;
        if (head.val == head.next.val){
            list = head;
            list = list.next;
        }

        while (head.next!=null){
            if (head.val==head.next.val&&head.next.next!=null){
                head = head.next;
                flag = true;
                continue;
            }
            if (flag){
                head = head.next;
                flag = false;
                continue;
            }
            list.next = head;
            list = list.next;
            head = head.next;
        }
        return list;
    }

    static class ListNode {
        int val;
        ListNode next;
        ListNode() {}
        ListNode(int val) { this.val = val; }
        ListNode(int val, ListNode next) { this.val = val; this.next = next; }
    }
    
}
